package com.itheima.health.controller;

import com.itheima.health.common.MessageConst;
import com.itheima.health.dto.OrderDTO;
import com.itheima.health.entity.Result;
import com.itheima.health.pojo.Order;
import com.itheima.health.service.OrderService;
import com.itheima.health.vo.OrderVO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 预约订单控制层
 */
@Slf4j
@RestController
@RequestMapping("/mobile/order")
public class OrderController {

    /**
     *  注入预约订单业务层对象
     */
    @Autowired
    private OrderService orderService;

    /**
     *  体检预约
     */
    @PostMapping("/submit")
    public Result submit(@RequestBody OrderVO orderVO){
        log.info("[体检预约-新增预约订单]orderVO:{}",orderVO);
        // 调用service层方法
        Order order = this.orderService.submit(orderVO);
        // 返回结果
        return new Result(true, MessageConst.ORDERSETTING_SUCCESS,order);
    }

    /**
     *  订单数据展示
     */
    @GetMapping("/findById")
    public Result findById(Integer id){
        log.info("[体检预约-订单数据展示]id:{}",id);
        // 调用service层方法
        OrderDTO orderDTO = this.orderService.findById(id);
        // 返回结果
        return new Result(true, MessageConst.ORDERSETTING_SUCCESS,orderDTO);
    }
}
